/* ---------------------------------------------------------------------------
   (c) Copyright 2006 ActivIdentity, Inc.
   All Rights Reserved.

   This program is an unpublished copyrighted work which is proprietary
   to ActivIdentity. This computer program includes Confidential,
   Proprietary Information and is a Trade Secret of ActivIdentity.
   Any use, disclosure, modification and/or reproduction is prohibited
   unless authorized in writing by ActivIdentity.

   WARNING:  Unauthorized reproduction of this program as well as
   unauthorized preparation of derivative works based upon the
   program or distribution of copies by sale, rental, lease or
   lending are violations of federal copyright laws and state trade
   secret laws, punishable by civil and criminal penalties.
   --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   Disclaimer

   ACTIVIDENTITY MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE 
   CONTENTS OR USE OF THIS SOFTWARE, AND SPECIFICALLY DISCLAIMS ANY EXPRESS
   OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
   PURPOSE. Further, ActivIdentity reserves the right to revise this software
   and to make changes to its content, at any time, without obligation to
   notify any person or entity of such revisions or changes.
   --------------------------------------------------------------------------- */

/*
 * Purpose: description of common structures and definitions for the SDK API.
 */

#ifndef __ACM_H__
#define __ACM_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Parameters */
#define IN
#define OUT
#define INOUT

#if defined(WIN32) || defined(WIN16) || defined(_WIN32_WCE)
/* Windows standard files and definitions */
#include <windows.h>
#else
/* Unix standard files and definitions */
#include <stdio.h>
#define CALLBACK
#define TRUE 1
#define FALSE 0
#endif

#include "device.h"

/***************/
/** CONSTANTS **/
/***************/

/*************/
/** MACROS **/
/*************/
#define ACM_HEX_LENGTH(binLength) (2*(binLength)+1)


/**********************/
/** TYPE DEFINITIONS **/
/**********************/

/* public accessors to retrieve the various parts of the version */
#define ACM_MAJOR_VERSION(x)		((int)(((unsigned int)(x)>>24)&0xFF))
#define ACM_MINOR_VERSION(x)		((int)(((unsigned int)(x)>>16)&0xFF))
#define ACM_BUILD_VERSION(x)		((int)(((unsigned int)(x)>>8)&0xFF))
/* --------------------- Constant --------------------------- */
#define ACM_VERS_VERSIONLEN			100	/* Max length for version */
#define ACM_VERS_COPYRIGHTLEN		256	/* Max length for copyright */
#define ACM_VERS_COMMENTLEN			256	/* Max length for comment */

/* --------------------- Value Size ------------------------- */
#define ACM_CHALLENGE_SIZE		(15+2+1+1)	/* len + sync param + check digit + '\0'*/
#define ACM_SERVER_CHALLENGE_SIZE (15+2+1+1)/* len + sync param + check digit + '\0'*/
#define ACM_OTP_SIZE			(15+2+1+1)	/* len + sync param + check digit + '\0'*/
#define ACM_MINI_PIN_SIZE		16		/* max len of the mini token software PIN */

#define ACM_CODE_SIZE			(ACM_OTP_SIZE + ACM_MINI_PIN_SIZE)	/* OTP size + PIN size */

#define ACM_CERT_NB				5			/* Nb data certification fields */
#define ACM_EXT_CERT_NB			16			/* Nb data certification fields in extended mode */
#define ACM_CERT_FIELD_SIZE		(23+1)		/* Max len of a certification field + '\0'*/
#define ACM_TOKEN_PIN_LEN		(8+1)
#define ACM_TOKEN_USERID_LEN	(20+1)


/* --------------------- key Size ------------------------- */
#define ACM_KEY_DES3_BITNB		16 /* binary triple DES key length */
#define ACM_KEY_DES1_BITNB		8 /* binary triple DES key length */
#define ACM_3KEY_DES1_BITNB		(3*8) /* binary triple DES key length */

#define ACM_KEY_DES3_CARNB		ACM_HEX_LENGTH(ACM_KEY_DES3_BITNB)/* hexa/ascii triple DES key length + '\0' */
#define ACM_KEY_DES1_CARNB		ACM_HEX_LENGTH(ACM_KEY_DES1_BITNB)/* hexa/ascii simple DES key length + '\0' */
#define ACM_3KEY_DES1_CARNB		ACM_HEX_LENGTH(ACM_3KEY_DES1_BITNB)/* hexa/ascii simple DES key length + '\0' */

/* For the fonts */
#define ACM_FONT_FILENAME_SIZE	(32+1)
#define ACM_FONT_SIZE			(240)

/* others */
#define ACM_NBMAX_SLOT		4	/* Number of slots in a device */

/*---------------------- Des Type --------------------------- */
#define	ACM_DES_TYPE_1			'1'		/* DES 1 */
#define	ACM_DES_TYPE_3			'3'		/* DES 3 */


/*---------------------- Check Digit Type ------------------------------ */
enum
{
	ACM_NO_CHECK_DIGIT = 0,
	ACM_CHECK_DIGIT = 1
};


/*---------------------- Counter Incrementation ------------------------ */
enum
{
	ACM_NO_INC_COUNTER = 0,
	ACM_INC_COUNTER = 1
};


/*---------------------- Key Derivation -------------------------------- */
enum
{
	ACM_NO_KEY_DERIV = 0,
	ACM_KEY_DERIV = 1
};


/*---------------------- Code Format ----------------------------------- */
enum
{
	ACM_DEC_FORMAT = 0,		/* Numeric format */
	ACM_HEX_FORMAT = 1,		/* Hexadecimal format */
	ACM_DEC_HEX_FORMAT = 2	/* Decimal or Hexadecimal format */

};

/*---------------------- "Software PIN" Position -----------------------*/
#define ACM_PIN_NONE			0
#define ACM_PIN_AFTER			1
#define ACM_PIN_BEFORE			2
#define ACM_PIN_BEFORE_OR_AFTER	3

#define ACM_PIN_CHECK			4

/*---------------------- Counter resynchronization Digit -----------------------*/
#define ACM_COUNTER_DIGIT_NONE		0
#define ACM_COUNTER_DIGIT_AFTER		1
#define ACM_COUNTER_DIGIT_BEFORE	2
#define ACM_COUNTER_DIGIT_STANDARD	3	/* ie OTP = 1 clock digit + 1 counter digit + OTP [+ 1 check digit] */

/*------------ Structures for Api functions -----------------------------*/

/* Structure for Extended Certification Data */
typedef struct strExtCertifDataTag
{
	char szField[ACM_EXT_CERT_NB][ACM_CERT_FIELD_SIZE];
	char cDecimalSep; /* Decimal separator character('.' or ',') */
} strExtCertifData;

typedef struct
{
  long		clock_begin;
  long		clock_end;
} StrClockRange;


typedef struct strAuthAsynchronousTag
{
	int		nTokMask;							/* Token mask type */
	char	cKeyType;							/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];			/* DES key */
	int 	nChalCkD;							/* Challenge check digit */
	int 	nRespFmt;							/* Response Format */
	int 	nRespCkD;							/* Response check digit */
	int 	nRespLn;							/* Length of the Response */
	char	szLastChal[ACM_CHALLENGE_SIZE];		/* Reserved for future use (RFU) */
} strAuthAsynchronous;

/* Structure for Synchronous Authentication API with re-synchro inside */
typedef struct strAuthSynchronousTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nKeyDerive;						/* Key derivation 0/1 */
	unsigned int ulCnt;						/* Value of the authentication counter*/
	int 	nCntInc;						/* Counter incrementation 0/1 */
	int 	nRespFmt;						/* Response format */
	int 	nRespCkD;						/* Response check digit */
	int 	nRespLn;						/* Length of the Response */
	int 	nExtractClock;					/* Number of extraction bits of the clock */
	int		lOffsetToken;					/* Token Offset */
	int		nAutoReSync;					/* RFU: Auto Resynchronization flag (for kernel 3 and upper) */
} strAuthSynchronous;

#define ACM_MAX_PIN_LEN	16
typedef struct strExtAuthSynchronousTag {
	int		nVersion;	/* RFU must be initialized to 0 */

	int		nTokMask;					/* Token mask type */
	char	cKeyType;					/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];	/* DES key */
	int 	nKeyDerive;					/* Key derivation 0/1 */
	unsigned int ulCnt;					/* Value of the authentication counter*/
	int 	nCntInc;					/* Counter incrementation 0/1 */
	int 	nRespFmt;					/* Response format */
	int 	nRespCkD;					/* Response check digit */
	int 	nRespLn;					/* Length of the Response */
	int 	nExtractClock;				/* Number of extraction bits of the clock */
	int		lOffsetToken;				/* Token Offset */
	int		nAutoReSync;				/* RFU: Auto Resynchronization flag (for kernel 3 and upper) */

	/* new fields used for Mini Synchronous Authentication */
	int 	nCounterResyncDigit;	/* position of the counter resynchronization digit in the OTP if any */
	int		nCounterResyncRange;	/* RFU: Max range of counter values to test on, if the nAutoReSync flag is on. 
									0 means use extended resynchronization default range (30). */
	int		nPINPosition;			/* position of the PIN concatenated to the OTP if any */
	int 	fPINCheck;				/* PIN verification flag */
	int 	nPINLen;				/* PIN length in bytes */
	int		nPINLenMin, nPINLenMax; /* RFU: Authorized length for change PIN */
	int		nMaxPINTry, nWrongPINTry; /* RFU: PIN try parameters */
	unsigned char ucPIN[ACM_MAX_PIN_LEN];		/* binary PIN value */

	unsigned int uInitFlags; /* various init flags, see ACM_MINI_INIT_* */

} strExtAuthSynchronous;

#define ACM_MINI_INIT_STARTUP_NODELAY	0x00000001
#define ACM_MINI_INIT_COUNTER_DISPLAY	0x00000002

/* Supported HOTP variants */
#define ACM_HOTP_STANDARD	1

#define ACM_INCREMENT_MOVING_FACTOR(lo,hi) {(lo)++; if ((lo) == 0) { (hi)++; }} 

typedef struct strHOTPAuthTag {
	int		nVersion;			/* RFU must be initialized to 0 */
	int		nDeviceType;		/* Device Type : ACM_MK_MINITOKEN_HOTP */

	int		nAlgoVersion;		/* ACM_HOTP_STANDARD */
	unsigned int	uAI;		/* Algorithm Identifier (RFU) */

	unsigned char	Secret[40];	/* Shared secret up to 2x160bits */
	int	nSecretLength;			/* Secret length in bytes */
	
	unsigned int uLoCounter;	/* Moving Factor: lo 32 bits */
	unsigned int uHiCounter;	/* Moving Factor: hi 32 bits */

	int	nWrongCodes;			/* Number of successive wrong codes received */
	int	nThrottlingParam;	/* Always return AK_ERR_BAD_AUTH_CODE if nWrongCodes >= nThrottlingParam (ie locked)
								no lock mecanism if equal to 0 */
	int	nResyncParam;		/* Check across S counter values */
	int	nAutoReSync;		/* Auto Resynchronization flag  */
	int	nOTPDigits;			/* OTP size without checksum if any */
	int	nTruncationOffset;	/* Truncation offset into the MAC if 0 ... 15, 16 = dynamic truncation */ 
	int fAddChecksum;		/* Flag to add checksum digit */

	int	nOTPToCheck;		/* Number of successives values to check for authentication */
	int	nUnlockOTPToCheck;	/* Number of successives values to check for unlock */

/* Software PIN handling */
	int	nPINPosition;		/* position of the PIN concatenated to the OTP if any */
	int fPINCheck;			/* PIN verification flag */
	int nPINLen;			/* PIN length in bytes */
	int	nPINLenMin, nPINLenMax; /* RFU: Authorized length for change PIN */
	int	nMaxPINTry, nWrongPINTry; /* RFU: PIN try parameters */
	unsigned char ucPIN[ACM_MAX_PIN_LEN];		/* binary PIN value */

	unsigned int uInitFlags; /* various init flags, see ACM_MINI_INIT_* */

} strHOTPAuth;

typedef struct strGeneralDataTag
{
	int		nTokMask;						/* Token mask type */
	char	aPinInitVal[ACM_TOKEN_PIN_LEN]; /* Pin Initial Value */
	long	lPinLnMin;						/* Pin Length Min */
	long	lPinLnMax;						/* Pin Length Max */
	long	lPinErrMax;						/* Pin Error Max */
	long	lPinWeak;						/* Pin Weak Control */
	long	lPinChg;						/* Pin change after first use */
	char	szUserID[ACM_TOKEN_USERID_LEN];	/* User ID for dynamic password */
} strGeneralData;

/* Extended Structure for Unlock API */
typedef struct strUnlockExTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	long	lUnlErrMax;
	char	cChallengeMode;
} strUnlockEx;

typedef struct strGetChallengeTag
{
	int	ChallengeMin;			/* Minimum supported length */
	int	ChallengeMax;			/* Maximum supported length */
	int	ChallengeLen;			/* Chosen length */
	int	ChallengeCheckDigit;	/* Check digit */
} strGetChallenge;

/* Structure for Unlock API */
typedef struct strUnlockTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nChalCkD;						/* Challenge check digit */
	int 	nRespCkD;						/* Response check digit */
} strUnlock;

/* Structure for Event Counter Synchronisation API */
typedef struct strSyncEventCntTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int		nKeyDerive;						/* Key derivation 0/1 */
	unsigned int ulCnt;						/* Value of the authentication or certification counter */
	int 	nCntInc;						/* Counter incrementation 0/1 */
} strSyncEventCnt;

/* Structure for Server Authentication API */
typedef struct strVerifServerTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
} strVerifServer;

/* Structure for Extended Asynchronous Certification API */
typedef struct strExtCertifAsyncTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nLnMax[ACM_EXT_CERT_NB];		/* Max Lengths of values to certificate */
	int  	nRespFmt;						/* Response format */
	int 	nRespLn;						/* Length of the Response */
	unsigned char ucPadChar;				/* Padding character */
	unsigned int nNbEffField;				/* Number of effective certification fields */
} strExtCertifAsync;

/* Structure for Extended Synchronous Certification API */
typedef struct strExtCertifSyncTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nKeyDerive;						/* Key derivation 0/1 */
	unsigned int ulCnt;						/* Value of the certification counter*/
	int 	nCntInc;						/* Counter incrementation 0/1 */
	int 	nLnMax[ACM_EXT_CERT_NB];		/* Max Lengths of values to certificate */
	int  	nRespFmt;						/* Response format */
	int 	nRespLn;						/* Length of the Response */
	int 	nExtractClock;					/* Number of extraction bits of the clock */
	int		lOffsetToken;					/* Token Offset */
	unsigned char ucPadChar;				/* Padding character */
	unsigned int nNbEffField;				/* Number of effective certification fields */
} strExtCertifSync;

/* Structure for Token Font */
typedef struct strTokenFontTag
{
	int		nTokMask;						/* Token mask type */
	int		nFontId;
	char	szFontFileName[ACM_FONT_FILENAME_SIZE];
	char	szTokenFont[ACM_FONT_SIZE];
} strTokenFont;

/********************** Deprecated */

/* For the static credentials */
#define ACM_SCR_DOMAIN_REALM	64
#define ACM_SCR_LOGIN_NAME		32
#define ACM_SCR_PASSWORD		32
#define ACM_SCR_CUSTOM_INFO		96
#define ACM_SCR_RESERVED		28

#define ACM_GLOBAL_OFFSET	0	/* obsolete token global offset */

/* Structure for Certification Data */
typedef struct strCertifDataTag
{
	char szField[ACM_CERT_NB][ACM_CERT_FIELD_SIZE];
	char cDecimalSep; /* Decimal separator character('.' or ',') */
} strCertifData;

/* Structure for Asynchronous Certification API */
typedef struct strCertifAsyncTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nLnMax[ACM_CERT_NB];			/* Max Lengths of values to certificate */
	int  	nRespFmt;						/* Response format */
	int 	nRespLn;						/* Length of the Response */
} strCertifAsync;

/* Structure for Synchronous Certification API */
typedef struct strCertifSyncTag
{
	int		nTokMask;						/* Token mask type */
	char	cKeyType;						/* DES Type [1]/[3] */
	char	szKey[ACM_KEY_DES3_CARNB];		/* DES key */
	int 	nKeyDerive;						/* Key derivation 0/1 */
	unsigned int ulCnt;						/* Value of the certification counter*/
	int 	nCntInc;						/* Counter incrementation 0/1 */
	int 	nLnMax[ACM_CERT_NB];			/* Max Lengths of values to certificate */
	int  	nRespFmt;						/* Response format */
	int 	nRespLn;						/* Length of the Response */
	int 	nExtractClock;					/* Number of extraction bits of the clock */
	int		lOffsetToken;					/* Token Offset */
} strCertifSync;

/* Structure for Static Credential API */
typedef struct strStaticCredentialTag
{
	char	szDomainRealm[ACM_SCR_DOMAIN_REALM+1];	/* Domain name */
	char	szLoginName[ACM_SCR_LOGIN_NAME+1];		/* Login name */
	char	szPassword[ACM_SCR_PASSWORD+1];			/* Static password */
	char	szCustomInfo[ACM_SCR_CUSTOM_INFO+1];	/* Custom information */
	char	szReserved[ACM_SCR_RESERVED+1];			/* Reserved for future use */
} strStaticCredential;

/* EMV Data Sizes in Bytes */
#define ACM_LEN_EMV_AUTH_TYPE			1
#define ACM_LEN_EMV_AUTH_VER			1
#define ACM_LEN_EMV_MAST_KEY_LBL		64 + 1
#define ACM_LEN_EMV_USER_PAN			16 + 1
#define ACM_LEN_EMV_USER_PSN			2 + 1
#define ACM_LEN_EMV_UNPR_NUM			9 + 1
#define ACM_LEN_EMV_IAF					1
#define ACM_LEN_EMV_CDOL1MASK			4
#define ACM_LEN_EMV_AMT_AUTH			6
#define ACM_LEN_EMV_AMT_OTHER			6
#define ACM_LEN_EMV_TERM_CNTY_CODE		2
#define ACM_LEN_EMV_TERM_VERF_RES		5
#define ACM_LEN_EMV_TRANS_CURR_CODE		2
#define ACM_LEN_EMV_TRANS_DATE			3
#define ACM_LEN_EMV_TRANS_TYPE			1
#define ACM_LEN_EMV_APPL_INTER_PR		2
#define ACM_LEN_EMV_APPL_TRANS_CTR		2
#define ACM_LEN_EMV_CARD_VERF_RES		4
#define ACM_LEN_EMV_KEY_DER_IDX			1
#define ACM_LEN_EMV_CRYPTO_VER_NUM		1
#define ACM_LEN_EMV_TERM_TYPE			1
#define ACM_LEN_EMV_AMT_REF_CURR		4
#define ACM_LEN_EMV_TRAN_REF_CURR_CODE	2
#define ACM_LEN_EMV_IIPB				43

#define ACM_LEN_EMV_ARQC_TRUNC			1
#define ACM_LEN_EMV_ATC_TRUNC			1
#define ACM_LEN_EMV_ATC_DELTA			2
#define ACM_LEN_EMV_MAXATCVALUE			2
#define ACM_LEN_EMV_AUTH_CODE			16 + 1

#define	ACM_EMV_TYPE_VISA					0
#define	ACM_EMV_TYPE_MASTERCARD_3D_CAP		ACM_EMV_TYPE_VISA				+1
#define	ACM_EMV_TYPE_APACS_AUTH				ACM_EMV_TYPE_MASTERCARD_3D_CAP	+1
#define	ACM_EMV_TYPE_APACS_PAYMENT			ACM_EMV_TYPE_APACS_AUTH			+1
#define	ACM_EMV_TYPE_ACTIVCARD				ACM_EMV_TYPE_APACS_PAYMENT		+1

#define ASYNC_AUTHENTICATION	1
#define SYNC_AUTHENTICATION		0

#define ACM_EMV_CVN_VISA10				10
#define ACM_EMV_CVN_VISA14				14
#define ACM_EMV_CVN_MASTERCARD_MCHIP21	200
#define ACM_EMV_CVN_MASTERCARD_MCHIP4	201

/* Structure for Synchronous/Asynchronous common EMV Authentication API */
typedef struct strEMVAuthTag
{
	char	nEMVAuthType;															/* Auth type: Visa, MasterCard 3D CAP, APACS or ActivCard EMV plus*/
	char	nEMVAuthVersion;														/* EMV Auth Version */
	char	szMasterKeyLabel[ACM_LEN_EMV_MAST_KEY_LBL];								/* ASCII HSM Master Key label + '\0' */
	char	szUserPAN[ACM_LEN_EMV_USER_PAN];										/* hexa/ascii + '\0'*/
	char	szUserPSN[ACM_LEN_EMV_USER_PSN];										/* hexa/ascii + '\0'*/
	char	szUnpredictableNumber[ACM_LEN_EMV_UNPR_NUM];							/* Challenge hexa/ascii + '\0'*/
	char	nInternetAuthenticationFlag[ACM_HEX_LENGTH(ACM_LEN_EMV_IAF)];			/* for MasterCard */
	char	szCVRMask[ACM_HEX_LENGTH(ACM_LEN_EMV_CDOL1MASK)];					/* CVR Mask */
	char	szAmountAuthorized[ACM_HEX_LENGTH(ACM_LEN_EMV_AMT_AUTH)];				/* AA hexa/ascii + '\0'*/
	char	szAmountOther[ACM_HEX_LENGTH(ACM_LEN_EMV_AMT_OTHER)];					/* AO hexa/ascii + '\0'*/
	char	szTerminalCountryCode[ACM_HEX_LENGTH(ACM_LEN_EMV_TERM_CNTY_CODE)];		/* TCC hexa/ascii + '\0'*/
	char	szTerminalVerificationResults[ACM_HEX_LENGTH(ACM_LEN_EMV_TERM_VERF_RES)];/* TVR hexa/ascii + '\0'*/
	char	szTransactionCurrencyCode[ACM_HEX_LENGTH(ACM_LEN_EMV_TRANS_CURR_CODE)];	/* TrCC hexa/ascii + '\0'*/
	char	szTransactionDate[ACM_HEX_LENGTH(ACM_LEN_EMV_TRANS_DATE)];				/* TrD hexa/ascii + '\0'*/
	char	szTransactionType[ACM_HEX_LENGTH(ACM_LEN_EMV_TRANS_TYPE)];				/* TrT hexa/ascii + '\0'*/
	char	szApplicationInterChangeProfile[ACM_HEX_LENGTH(ACM_LEN_EMV_APPL_INTER_PR)];/* AICP hexa/ascii + '\0'*/
	char	szApplicationAndTransactionCounter[ACM_HEX_LENGTH(ACM_LEN_EMV_APPL_TRANS_CTR)];/* ATC hexa/ascii + '\0'*/
	char	szCardVerificationResults[ACM_HEX_LENGTH(ACM_LEN_EMV_CARD_VERF_RES)];	/* CVR hexa/ascii + '\0'*/
	char	szDerivationKeyIndex[ACM_HEX_LENGTH(ACM_LEN_EMV_KEY_DER_IDX)];			/* KDI hexa/ascii + '\0'*/
	char	szCryptogramVersionNumber[ACM_HEX_LENGTH(ACM_LEN_EMV_CRYPTO_VER_NUM)];	/* CVN hexa/ascii + '\0'*/
	char	szTerminalType[ACM_HEX_LENGTH(ACM_LEN_EMV_TERM_TYPE)];					/* RFU TT hexa/ascii + '\0' MasterCard only (RFU)*/
	char	szAmountReferenceCurrency[ACM_HEX_LENGTH(ACM_LEN_EMV_AMT_REF_CURR)];	/* RFU ARC hexa/ascii + '\0' MasterCard only (RFU)*/
	char	szExtCVRMask[ACM_HEX_LENGTH(ACM_LEN_EMV_TRAN_REF_CURR_CODE)];	/* Extended CVR Mask if MChip4 */
	char	szIIPB[ACM_HEX_LENGTH(ACM_LEN_EMV_IIPB)];								/* hexa/ascii + '\0' MasterCard only (RFU)*/
	char	cTruncatedARQLength;													/* hexa/ascii + '\0' Proton Digit N */
	char	cTruncatedATCLength;													/* hexa/ascii + '\0' Proton Digit M */
	char    cATCDelta[ACM_HEX_LENGTH(ACM_LEN_EMV_ATC_DELTA)]; 						/* Authorized delta between OTC ATC and backend ATC - RFU */
	char    szExtCVR[ACM_HEX_LENGTH(ACM_LEN_EMV_MAXATCVALUE)]; 				/* Extended CVR if MChip4 */
	char	szUpdatedApplicationAndTransactionCounter[ACM_HEX_LENGTH(ACM_LEN_EMV_APPL_TRANS_CTR)];/* ATC hexa/ascii + '\0'*/
	char	szEMVAuthCode[ACM_LEN_EMV_AUTH_CODE];

} strEMVAuth;

typedef struct acEMVAuthContextTag {
	int (CALLBACK *pacEMVCBFormatInputData) (IN void* context, 
									IN strEMVAuth *pAuth, 
									IN int nAuthType, 
									INOUT int* pnInputDataLength, 
									OUT char* pszInputData);

	int (CALLBACK *pacEMVCBGenerateCryptogram)	(IN void* context, 
										 IN strEMVAuth *pAuth, 
										 IN int nAuthType, 
										 IN char* pszInitvalue,
										 IN char* pszInputData, 
										 INOUT int* pnCryptogramLength, 
										 OUT char* pszCryptogram);

	int (CALLBACK *pacEMVCBFormatResponse)		(IN void* context, 
										 IN strEMVAuth *pAuth, 
										 IN int nAuthType, 
										 IN char* pszCryptogram, 
										 INOUT int* pnResponseLength, 
										 OUT char* pszResponse); 
	/* RFU callback */
	int (*pacRFU)(void);
	void* pCBContext;
} acEMVAuthContext;

#ifdef __cplusplus
}
#endif

#endif /* __ACM_H__ */
